<!--
医院管理-医院维护增加
 add by yyp 2020-01-12
-->
<template lang="pug">
  kalix-dialog.user-add(bizKey="Hospital" ref="kalixBizDialog" v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" v-bind:submitCustom="submitCustom")
    div.el-form(slot="dialogFormSlot" style=" width:60%;margin:auto;")
      el-form-item(label="医院名称" prop="hospitalName" v-bind:label-width="labelWidth" v-bind:rules="rules.hospitalName")
        el-input(v-model="formModel.hospitalName" style="width:80%")
      el-form-item(label="医院地址" prop="hospitalAdress" v-bind:label-width="labelWidth" v-bind:rules="rules.hospitalAdress")
        el-input(v-model="formModel.hospitalAdress" style="width:80%")
      el-form-item(label="医院LOGO" prop="hospitalLogo" v-bind:label-width="labelWidth" v-bind:rules="rules.hospitalLogo")
        kalix-upload(v-model="formModel.hospitalLogo" v-bind:isImage="true" style="width:100%")
</template>

<script type="text/ecmascript-6">
  import FormModel from './model'
  import {HospitalURL} from '../../config.toml'
  import KalixClansmanUpload from '../../../../../components/fileUpload/upload'
  import {baseURL} from '../../../../../config/global.toml'
  import KalixSelect from '../../../../../components/corelib/components/common/baseSelect'
  export default {
    name: 'hospitalAdd',
    components: {KalixSelect, KalixClansmanUpload},
    data() {
      let validateHospitalName = (rule, value, callback) => {
        if (value === null) {
          callback(new Error('请输入医院名称'))
        } else {
          this.axios.request({
            method: 'GET',
            url: HospitalURL + '/existUserBeanByLoginName/',
            data: '',
            params: {
              hospitalName: value
            }
          }).then(response => {
            if (response.data) {
              callback(new Error('该医院名称已被使用'))
            } else {
              callback()
            }
          }).catch(() => {
          })
        }
      }
      return {
        formModel: Object.assign({}, FormModel),
        action: baseURL + '/camel/rest/upload',
        rules: {
          // hospitalName: [{required: true, message: '请输入医院名称', trigger: 'blur'}],
          hospitalName: [{required: true, validator: validateHospitalName, trigger: 'blur'}]
        },
        targetURL: HospitalURL,
        labelWidth: '150px'
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">
  .el-form
    width 70%
    margin auto
    .el-input
      width 70%
    .radio
      margin-left 20px
      .el-radio
        color: #3465cb
        font-weight: bold
        font-size: 14px
</style>
